package com.wei.file.serve;

import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class CodeTypeParse {


    private final Map<String,String> extOfTypeMap;



    public String getCodeType(String filename){
        String codeType="plaintext";
        filename=  filename.toLowerCase();
        for(var ext :this.extOfTypeMap.keySet()){
            if(filename.endsWith("."+ext)){
                return this.extOfTypeMap.get(ext);
            }
        }
        return codeType;
    }

    public CodeTypeParse(){
        this.extOfTypeMap = new HashMap<>();
        this.extOfTypeMap.put("py","python");
        this.extOfTypeMap.put("php","php");
        this.extOfTypeMap.put("c","c");
        this.extOfTypeMap.put("cpp","cpp");
        this.extOfTypeMap.put("css","css");
        this.extOfTypeMap.put("java","java");
        this.extOfTypeMap.put("json","json");
        this.extOfTypeMap.put("md","markdown");
        this.extOfTypeMap.put("scss","scss");
        this.extOfTypeMap.put("qml","qml");
        this.extOfTypeMap.put("sql","sql");
        this.extOfTypeMap.put("html","html");
        this.extOfTypeMap.put("htm","html");
        this.extOfTypeMap.put("ts","typescript");
        this.extOfTypeMap.put("xml","xml");
        this.extOfTypeMap.put("yaml","yaml");
        this.extOfTypeMap.put("yml","yaml");
    }
}
